package peer.dstdb.message;

import java.net.DatagramPacket;

import peer.Message;
import peer.tools.ByteShortSwitch;


public class SourceSearchMessage extends Message{
	public short sType=peer.tools.MessageType.sType_DB_SourceSearchMessage;
	byte[] dpData=null;
	byte[] md=null;
	short blockNum;
	public SourceSearchMessage(byte[] md,short blockNum){
		this.md=md;
		this.blockNum=blockNum;
		dpData=new byte[22];
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		System.arraycopy(md, 0, dpData, 4,16);
		ByteShortSwitch.toByteArray(blockNum, dpData, 20);
		dp=new DatagramPacket(dpData,dpData.length);
	}
	
	public SourceSearchMessage(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		md=new byte[16];
		blockNum=ByteShortSwitch.toShort(dpData, 20);
		System.arraycopy(dpData, 4, md, 0, 16);
	}
	
	public byte[] getMd(){
		return md;
	}
	
	public short getBlockNum(){
		return blockNum;
	}
}
